package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.enums.SupportBusinessTypeEnum;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfwDoc.dto.TemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.dto.dto.SqfwShopBaseInfoDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownExcelLedgerReqVo;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownFileTypesResVo;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.FormSummaryNewQueryReqVo;
import com.budwk.app.sqfwV2.dto.entity.SqfwShopsBaseInfo;
import com.budwk.app.sqfwV2.service.DayingRoadService;
import com.budwk.app.sqfwV2.service.ShopsBaseInfoService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author yg
 * @since 2024/01/23
 */

@IocBean
@At("/platform/sqfwV2/dayingRoad")
@ApiDefinition(tag = "大营路街道接口（字典系统）")
@Slf4j
public class DayingRoadController {

    @Inject
    private DayingRoadService dayingRoadService;
    @Inject
    private ShopsBaseInfoService shopsBaseInfoService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "提交数据/生成PDF")
    @ApiFormParams(implementation = TemplateCodeUpdateDTO.class)
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SLog(tag = "大营路街道新增接口", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> submitData(@Param("..") TemplateCodeUpdateDTO dto) {
        log.info("DayingRoadController submitData param: {}", JSONObject.toJSONString(dto));
        dayingRoadService.submitData(dto);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "重新生成PDF")
    @SaCheckLogin
    public Result<?> reGeneratePDF(@Param("sqfwFlowId") String sqfwFlowId) {
        log.info("DayingRoadController reGeneratePDF sqfwFlowId: {}", sqfwFlowId);
        return dayingRoadService.reGeneratePDF(sqfwFlowId);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "下载Excle台账(按照编码下载)（支持批量下载）")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> downExcelLedger(@Param("..") DownExcelLedgerReqVo reqVo) {
        log.info("DayingRoadController downExcelLedger reqVo: {}", JSONObject.toJSONString(reqVo));
//        reqVo.setAgainGenerate(true);
        return dayingRoadService.downExcelLedger(reqVo);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "下载pdf文档")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> downPdfFile(@Param("..") DownExcelLedgerReqVo reqVo) {
        log.info("DayingRoadController downExcelLedger reqVo: {}", JSONObject.toJSONString(reqVo));
        return dayingRoadService.downPdfFile(reqVo);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "根据输入的查询条件和内容查询列表信息")
    @ApiResponses(implementation = Sqfw_formSummary_new.class)
    @SaCheckLogin
    public Result<?> listByConditionKey(@Param("content") String content, @Param("conditionKey") String conditionKey) {
        log.info("DayingRoadController listByConditionKey content: {}, conditionKey: {}", content, conditionKey);
        return dayingRoadService.listByConditionKey(conditionKey, content, SupportBusinessTypeEnum.SAFETY_CHECK.getName());
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "下载文件列表数据")
    @ApiResponses(implementation = DownFileTypesResVo.class)
    @SaCheckLogin
    public Result<List<DownFileTypesResVo>> listDownFileTypes(@Param("sqfwId") String sqfwId) {
        log.info("DayingRoadController listDownFileTypes start");
        return dayingRoadService.listDownFileTypes(sqfwId);
    }

    @At
    @GET
    @ApiOperation(name = "下载pdf模板")
    public void downPdfTemplate(HttpServletResponse response) {
        log.info("DayingRoadController downPdfTemplate start");
        dayingRoadService.downPdfTemplate(response);
    }

    @At
    @GET
    @ApiOperation(name = "下载word模板")
    public void downWordTemplate(HttpServletResponse response) {
        log.info("DayingRoadController downWordTemplate start");
        dayingRoadService.downWordTemplate(response);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "分页查询后台列表查询")
    @ApiFormParams(implementation = FormSummaryNewQueryReqVo.class)
    @ApiResponses(implementation = Sqfw_formSummary_new.class)
    @SaCheckLogin
    public Result<?> listAdminByPage(@Param("..") FormSummaryNewQueryReqVo reqVo) {
        log.info("DayingRoadController listAdminByPage param: {}", JSONObject.toJSONString(reqVo));
        return dayingRoadService.listAdminByPage(reqVo);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "停业状态修改")
    @ApiResponses
    @SaCheckLogin
    public Result<?> changeCloseDown(@Param("id") String id) {
        dayingRoadService.changeCloseDown(id);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询商铺信息(五级查询)")
    @ApiFormParams(implementation = SqfwShopBaseInfoDTO.class)
    @ApiResponses(implementation = SqfwShopsBaseInfo.class)
    @SaCheckLogin
    public Result<?> listShopByPage(@Param("..") SqfwShopBaseInfoDTO baseInfo) {
        log.info("shop listShopByPage param: {}", JSONObject.toJSONString(baseInfo));
        return dayingRoadService.listShopByPage(baseInfo);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询商铺信息(分页同单位的数据)")
    @ApiFormParams(implementation = SqfwShopBaseInfoDTO.class)
    @ApiResponses(implementation = SqfwShopsBaseInfo.class)
    @SaCheckLogin
    public Result<Pagination> listCurrentUserShop(@Param("..") SqfwShopBaseInfoDTO baseInfo) {
        log.info("shop listCurrentUserShop param: {}", JSONObject.toJSONString(baseInfo));
        return dayingRoadService.listCurrentUserShop(baseInfo);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询商铺信息")
    @ApiResponses(implementation = Sqfw_formSummary_new.class)
    @SaCheckLogin
    public Result<?> getShopDetailById(@Param("shopId") String shopId) {
        Sqfw_formSummary_new formSummaryNew = shopsBaseInfoService.getShopDetailById(shopId);
        return Result.data(formSummaryNew);
    }
}












